home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / misc / pdflib / imagepdf.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  2KB  |  118 lines

  1. /* imagepdf.c
  2.  * Copyright (C) 1997-98 Thomas Merz. All rights reserved.
  3.  *
  4.  * Convert TIFF/GIF/JPEG images to PDF
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12. #ifdef POSIX
  13. #include <unistd.h>
  14. #endif
  15.  
  16. #ifdef DOS
  17. #include <process.h>
  18. #endif
  19.  
  20. #ifdef NeXT
  21. #include <libc.h>    /* for getopt(), optind, optarg */
  22. #endif
  23.  
  24. #include "pdf.h"
  25.  
  26. static void
  27. usage(void)
  28. {
  29.     fprintf(stderr, "imagepdf - Convert ");
  30. #ifdef USE_TIFF
  31.     fprintf(stderr, "TIFF/");
  32. #endif
  33.     fprintf(stderr, "GIF/JPEG images to PDF. (C) Thomas Merz 1997\n");
  34.     fprintf(stderr, "usage: imagepdf [options] imagefile(s)\n");
  35.     fprintf(stderr, "Available options:\n");
  36.     fprintf(stderr, "-a         ASCII mode (default: binary)\n");
  37.     fprintf(stderr, "-c         print caption\n");
  38.     fprintf(stderr, "-o <file>  output file\n");
  39.  
  40.     exit(1);
  41. }
  42.  
  43. void
  44. main(int argc, char *argv[])
  45. {
  46.     PDF_info    *info;
  47.     FILE    *pdffile = NULL;
  48.     PDF        *p;
  49.     PDF_image    *image;
  50.     int        opt;
  51.     bool    caption = false;
  52.     float    scale;
  53.     
  54.     info        = PDF_get_info();
  55.     info->binary_mode    = true;
  56.     info->Creator       = "imagepdf";
  57.  
  58.     while ((opt = getopt(argc, argv, "ao:")) != -1)
  59.     switch (opt) {
  60.         case 'a':
  61.         info->binary_mode = false;
  62.         break;
  63.  
  64.         case 'c':
  65.         caption = true;
  66.         break;
  67.  
  68.         case 'o':
  69.         if ((pdffile = fopen(optarg, WRITEMODE)) == NULL) {
  70.             fprintf(stderr, 
  71.                 "Error: cannot open output file %s.\n", optarg);
  72.             exit(1);
  73.         }
  74.         break;
  75.     }
  76.  
  77.     if (optind == argc) {
  78.     fprintf(stderr, "Error: no image files given.\n");
  79.     usage();
  80.     }
  81.  
  82.     if (pdffile == NULL) {
  83.     fprintf(stderr, "Error: no output file given.\n");
  84.     usage();
  85.     }
  86.  
  87.     p = PDF_open(pdffile, info);
  88.  
  89.     while (optind++ < argc) {
  90.     fprintf(stderr, "Processing image file %s...\n", argv[optind-1]);
  91.  
  92.     if ((image = PDF_open_GIF(p, argv[optind-1])) == NULL &&
  93. #ifdef USE_TIFF
  94.         (image = PDF_open_TIFF(p, argv[optind-1])) == NULL &&
  95. #endif
  96.         (image = PDF_open_JPEG(p, argv[optind-1])) == NULL) {
  97.         fprintf(stderr,"Error: Couldn't analyze image %s - skipped.\n",
  98.                 argv[optind-1]);
  99.         continue;
  100.     }
  101.  
  102.     scale = 1.0;
  103.  
  104.     PDF_begin_page(p, image->width * scale, image->height * scale);
  105.     
  106.     /* define outline with filename */
  107.     PDF_add_outline(p, image->filename);
  108.  
  109.     PDF_place_image(p, image, 0.0, 0.0, scale);
  110.     PDF_close_image(p, image);
  111.  
  112.     PDF_end_page(p);
  113.     }
  114.  
  115.     PDF_close(p);
  116.     exit(0);
  117. }
  118.